﻿using System;
using System.Collections.Generic;
using System.Reflection;
using CoreEx.Database.Metadata;

namespace CoreEx.Database.MetaData.Implementation
{
    /// <summary>
    /// Represents the mapping between type and a database table.
    /// </summary>
    public class TypeMappingInfo : ITypeMappingInfo
    {        
        /// <summary>
        /// Gets or sets the target <see cref="Type"/>.
        /// </summary>
        public Type Type { get; set; }
        
        /// <summary>
        /// Gets or sets the <see cref="TableInfo"/> that represents
        /// the table that the <see cref="Type"/> is mapped to.
        /// </summary>
        public TableInfo TableInfo { get; set; }
        
        /// <summary>
        /// Gets or sets a list of <see cref="PropertyMappingInfo"/> instances that 
        /// describes the mapping between properties and table columns.
        /// </summary>
        public IDictionary<PropertyInfo, IPropertyMappingInfo> ColumnMappings { get; set;}

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            if (Type != null && TableInfo != null)
                return string.Format("Type {0} => {1} table.", Type.Name, TableInfo.TableName);

            return base.ToString();

        }
    }
}
